﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;

namespace SZ
{
    public class RemoveLayers : BaseCommand
    {
        private IMapControl3 m_mapControl = null;
        private TreeView m_treeView = null;

        public RemoveLayers(TreeView treeView)
        {
            base.m_caption = "移除图层";
            m_treeView = treeView;
        }

        public override void OnClick()
        {

            ILayer pLayer = m_mapControl.CustomProperty as ILayer;

            m_mapControl.Map.DeleteLayer(pLayer);
            
            //连接数据库
            //ConnectSDE connectSde = new ConnectSDE();
            //IWorkspace pWorkspace = connectSde.SdeWorkspace();
            string nodeValue = pLayer.Name;
            TreeViewClass treeViewClass = new TreeViewClass();
            TreeNode treeNode = treeViewClass.searchNode(nodeValue, m_treeView);
            if(treeNode.Checked = true )
            {
                treeNode.Checked = false;
            }
            m_mapControl.ActiveView.Refresh();
            GC.Collect();
        }

        public override void OnCreate(object hook)
        {
            m_mapControl = (IMapControl3)hook;
        }



    }
}
